// CharString.cpp

// Implementacia retazca zlozeneho z charov

#include <string.h>
#include "Common/Protocol/CharString.h"

// Konstruktor
CharString::CharString(const char* pStr)
{
	if (pStr && strlen(pStr)) {
		m_pStr = new char[strlen(pStr) + 1];
		strcpy(m_pStr, pStr);
	}
	else m_pStr = NULL;
}

// Kopirovaci konstruktor
CharString::CharString(const CharString& str)
{
	if (str.m_pStr) {
		m_pStr = new char[strlen(str.m_pStr) + 1];
		strcpy(m_pStr, str.m_pStr);
	}
	else m_pStr = NULL;
}

// Destruktor
CharString::~CharString()
{
	if (m_pStr)
		delete[] m_pStr;
}


// Operatory

// Operator pretypovania na (char*)
CharString::operator char*()
{
/*	char* pStr;

	if (m_pStr) {
		pStr = new char[strlen(m_pStr) + 1];
		strcpy(pStr, m_pStr);
	}
	else {
		pStr = new char;
		*pStr = 0;
	}
*/
	return m_pStr;
}

/*
CharString CharString::operator +(const char* pStr)
{
	char* pTmp;

	pTmp = new char[strlen(m_pStr) + strlen(pStr) + 1];
	strcat(strcpy(pTmp, m_pStr), pStr);

	return CharString(pTmp, 0);
}

CharString CharString::operator+(const CharString& str)
{
	char* pTmp;

	pTmp = new char[strlen(m_pStr) + strlen(str.m_pStr) + 1];
	strcat(strcpy(pTmp, m_pStr), str.m_pStr);

	return CharString(pTmp, 0);
}

CharString operator+(const char* pStr, const CharString& str)
{
	char* pTmp;

	pTmp = new char[strlen(pStr) + strlen(str.m_pStr) + 1];
	strcat(strcpy(pTmp, pStr), str.m_pStr);

	return CharString(pTmp, 0);
}
*/

/*
CharString& CharString::operator=(const char* pStr)
{
	if (m_pStr) delete[] m_pStr;
	if (pStr && strlen(pStr)) {
		m_pStr = new char[strlen(pStr) + 1];
		strcpy(m_pStr, pStr);
	}
	else m_pStr = NULL;

	return *this;
}

CharString& CharString::operator=(const CharString& str)
{
	if (m_pStr) delete[] m_pStr;
	if (str.m_pStr) {
		m_pStr = new char[strlen(str.m_pStr) + 1];
		strcpy(m_pStr, str.m_pStr);
	}
	else m_pStr = NULL;

	return *this;
}
*/
/*
int CharString::operator==(const char* pStr)
{
	return strcmp(m_pStr, pStr);
}

int CharString::operator==(const CharString& str)
{
	return strcmp(m_pStr, str.m_pStr);
}

int operator==(const char* pStr, const CharString& str)
{
	return strcmp(pStr, str.m_pStr);
}
*/


